package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.DeviceDataByDayDto;
import com.zzyl.nursing.dto.QueryDevicePropertyStatusRequestDto;
import com.zzyl.nursing.dto.UserAddRequestDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.mapper.FamilyMemberElderMapper;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 *
 * @author alexis
 * @date 2025-01-09
 */
@Api(tags = "老人家属管理")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private FamilyMemberElderMapper familyMemberElderMapper;

    @PostMapping("/login")
    public R<LoginVo> login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        // 调用Service层接口进行小程序登录
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return R.ok(loginVo);
    }

    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody UserAddRequestDto userAddRequestDto) {
        familyMemberService.add(userAddRequestDto);
        return success();
    }
    @DeleteMapping("/deleteById")
    @ApiOperation("解绑家人")
    public AjaxResult deleteById(Long id) {
        familyMemberService.removeById(id);
        return success();
    }

    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public R<List<FamilyMemberElderVo>> selectMyElderList() {
        return R.ok(familyMemberService.selectMyElderList());
    }

    @GetMapping("/list-by-page")
    @ApiOperation("查看已绑定家人列表（分页查询）")
    public R<List<FamilyMemberElderBedVo>> selectMyElderListByPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        return R.ok(familyMemberService.selectMyElderListByPage(pageNum, pageSize));
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public R<PropertyStatusInfoVo> queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequestDto queryDevicePropertyStatusRequestDto) {

        return R.ok(familyMemberService.queryDevicePropertyStatus(queryDevicePropertyStatusRequestDto));
    }

    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public R<List<DeviceDataByDayVo>> queryDeviceDataListByDay(DeviceDataByDayDto deviceDataByDayDto) {
        return R.ok(familyMemberService.queryDeviceDataListByDay(deviceDataByDayDto));
    }

    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public R<List<DeviceDataByDayVo>> queryDeviceDataListByWeek(DeviceDataByDayDto deviceDataByDayDto) {
        return R.ok(familyMemberService.queryDeviceDataListByWeek(deviceDataByDayDto));
    }


}
